/**
 * 
 */
package View;

import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import Model.contact;

/**
 * @author enzo
 *
 */
public class ContactView extends JPanel {
	private JPanel fieldPan;
	private JLabel labelAddress;
	private JLabel labelCompanyAddress;
	private JLabel labelPhoneperso; 
	private JLabel labelPhonepro; 
	private JLabel labelURL;
	private JLabel labelEmailPerso;
	private JLabel labelEmailPro;
	private JLabel labelGroup;
	private JLabel name,address,companyAddress,phonePerso,phonePro,url,emailPerso,emailPro,group;
	private JButton modify;
	
	/**
	 * 
	 */
	public ContactView()
	{
		setLayout(new BorderLayout());
		fieldPan=new JPanel();
		fieldPan.setLayout(new GridLayout(8,2));
		labelAddress=new JLabel("Address : ");
		labelCompanyAddress=new JLabel("CompanyAddress :");
		labelPhoneperso = new JLabel("Personal phone number :");
		labelPhonepro=new JLabel("Professional phone number:");
		labelURL=new JLabel("webpage :");
		labelEmailPerso= new JLabel("Email perso :");
		labelEmailPro=new JLabel("Email pro : ");
		labelGroup=new JLabel("Group : ");
		address=new JLabel();
		companyAddress=new JLabel();
		phonePerso=new JLabel();
		phonePro=new JLabel();
		url=new JLabel();
		group=new JLabel();
		url.setCursor(new Cursor(Cursor.HAND_CURSOR));
		emailPerso=new JLabel();
		emailPro=new JLabel();
		name=new JLabel("", SwingConstants.CENTER);
		fieldPan.add(labelAddress);
		fieldPan.add(address);
		fieldPan.add(labelCompanyAddress);
		fieldPan.add(companyAddress);
		fieldPan.add(labelPhoneperso);
		fieldPan.add(phonePerso);
		fieldPan.add(labelPhonepro);
		fieldPan.add(phonePro);
		fieldPan.add(labelEmailPerso);
		fieldPan.add(emailPerso);
		fieldPan.add(labelEmailPro);
		fieldPan.add(emailPro);
		fieldPan.add(labelURL);
		fieldPan.add(url);
		fieldPan.add(labelGroup);
		fieldPan.add(group);
		
		modify=new JButton("Alter");
		this.add("North",name);
		this.add("South",modify);
		this.add("Center",fieldPan);
		this.setVisible(true);
		
		
	}
	/**
	 * @param c
	 */
	public void displayContact(contact c)
	{
		name.setText(c.getFirstname()+ " " +c.getName());
		ImageIcon picture=new ImageIcon(c.getPhoto());
		picture.setImage(picture.getImage().getScaledInstance(100, 100, Image.SCALE_DEFAULT));
		name.setIcon(picture);
		name.setIconTextGap(30);
		Font nameFont = new Font("Serif", Font.BOLD, 15);
		name.setFont(nameFont);
		if(c.getAddress()=="") address.setText(" ");
		else address.setText(c.getAddress());
		if(c.getCompanyAddress()=="") companyAddress.setText(" ");
		else companyAddress.setText(c.getCompanyAddress());
		if(c.getPhoneperso()=="") phonePerso.setText(" ");
		else phonePerso.setText(c.getPhoneperso());
		if(c.getPhonepro()=="") phonePro.setText(" ");
		else phonePro.setText(c.getPhonepro());
		if(c.getEmailPerso()=="") emailPerso.setText(" ");
		else emailPerso.setText(c.getEmailPerso());
		if(c.getEmailPro()=="") emailPro.setText(" ");
		else emailPro.setText(c.getEmailPro());
		if(c.getURL()=="") url.setText(" ");
		else url.setText(c.getURL());
		if(c.getGroup()=="") group.setText(" ");
		else group.setText(c.getGroup());
	}
	/**
	 * @return the modify
	 */
	public JButton getModify() {
		return modify;
	}
	/**
	 * @return the url
	 */
	public JLabel getUrl() {
		return url;
	}
	/**
	 * @return the emailPerso
	 */
	public JLabel getEmailPerso() {
		return emailPerso;
	}
	/**
	 * @return the emailPro
	 */
	public JLabel getEmailPro() {
		return emailPro;
	}

}
